<?php

class Application_Form_Register extends Zend_Form {

    public function init() {
        $this->setAction('/default/auth/register')
                ->setMethod('post')
                ->setAttrib('id', 'registerForm')
                ->addElementPrefixPath('ZendBlog_Validate', 'ZendBlog/validate/', 'validate')
                ->setDecorators(ZendBlog_Decorator_Decorator::Form());

        /* Username */
        $this->addElement('text', 'username', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Username',
            'validators' => array('alnum', array(
                    'db_NoRecordExists', false,
                    array(
                        'table' => 'users',
                        'field' => 'username'
                ))
            ),
            'filter' => array('StringTrim', 'StringToLower'),
            'required' => true
        ));

        /* Name */
        $this->addElement('text', 'name', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Name',
            'attribs' => array(
                'size' => 40
            ),
            'required' => true
        ));

        /* Email */
        $this->addElement('text', 'email', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Email',
            'validators' => array('emailAddress', array(
                    'db_NoRecordExists', false,
                    array(
                        'table' => 'users',
                        'field' => 'email'
                ))
            ),
            'filter' => array('StringTrim', 'StringToLower'),
            'attribs' => array(
                'size' => 40
            ),
            'required' => true
        ));

        /* Password */
        $this->addElement('password', 'password', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Password',
            'validators' => array('PasswordConfirmation',
                array('stringLength', true, array(4))
            ),
            'filter' => 'StringTrim',
            'required' => true
        ));

        /* Confirm Password */
        $this->addElement('password', 'password_confirm', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => 'Confirm Password',
            'validators' => array('PasswordConfirmation',
                array('stringLength', true, array(4))
            ),
            'filter' => 'StringTrim',
            'required' => true
        ));

        /* Captcha */
        $this->addElement('captcha', 'captcha', array(
            'decorators' => ZendBlog_Decorator_Decorator::Element(),
            'label' => "Verify captcha",
            'captcha' => array(
                'captcha' => 'image',
                'font' => './font/ARLRDBD.ttf',
                'imgDir' => './captcha/',
                'imgUrl' => 'http://' . $_SERVER['SERVER_NAME'] . '/captcha/',
                'wordLen' => 4,
                'fsize' => 30,
                'height' => 40,
                'width' => 150,
                'gcFreq' => 10,
                'expiration' => 300
            )
        ));

        /* Register button */
        $this->addElement('submit', 'Register', array(
            'decorators' => ZendBlog_Decorator_Decorator::Submit()
        ));
    }

}

